package com.ruibang.glass.material.service.impl.cp;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.domain.req.bcp.MaterialBCPInventoryReq;
import com.ruibang.glass.material.entity.cp.MaterialCPInventoryManagement;
import com.ruibang.glass.material.mapper.cp.GMaterialCPInventoryManagementMapper;
import com.ruibang.glass.material.service.cp.GMaterialCPInventoryManagementService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 原材料库存管理表 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-04-01
 */
@Service
public class GMaterialCPInventoryManagementServiceImpl extends ServiceImpl<GMaterialCPInventoryManagementMapper, MaterialCPInventoryManagement> implements GMaterialCPInventoryManagementService {

    @Override
    public IPage<MaterialCPInventoryManagement> getPage(MaterialBCPInventoryReq materialInventoryReq) {
        LambdaQueryWrapper<MaterialCPInventoryManagement> queryWrapper = Wrappers.<MaterialCPInventoryManagement>lambdaQuery();
        if (StringUtils.isNotBlank(materialInventoryReq.getMaterialCode())) {
            queryWrapper.like(MaterialCPInventoryManagement::getMaterialCode, materialInventoryReq.getMaterialCode());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBatchNumber())) {
            queryWrapper.like(MaterialCPInventoryManagement::getBatchNumber, materialInventoryReq.getBatchNumber());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getStorageLocation())) {
            queryWrapper.like(MaterialCPInventoryManagement::getStorageLocation, materialInventoryReq.getStorageLocation());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getLevelFinish())) {
            queryWrapper.eq(MaterialCPInventoryManagement::getLevelFinish, materialInventoryReq.getLevelFinish());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getSpecification())) {
            queryWrapper.eq(MaterialCPInventoryManagement::getSpecification, materialInventoryReq.getSpecification());
        }

        Page<MaterialCPInventoryManagement> materialWarehouseInfoPage = baseMapper.selectPage(new Page<>(materialInventoryReq.getPageNo(), materialInventoryReq.getPageSize()),
                queryWrapper.orderByDesc(MaterialCPInventoryManagement::getCreateTime)
        );
        return materialWarehouseInfoPage;

    }
}
